home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWEmbUtl.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  7.4 KB  |  260 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWEmbUtl.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWEMBUTL_H
  13. #include "FWEmbUtl.h"
  14. #endif
  15.  
  16. #ifndef FWFILESP_H
  17. #include "FWFileSp.h"
  18. #endif
  19.  
  20. #ifndef FWACQUIR_H
  21. #include "FWAcquir.h"
  22. #endif
  23.  
  24. #ifndef FWBARRAY_H
  25. #include "FWBArray.h"
  26. #endif
  27.  
  28. #ifndef FWCLNINF_H
  29. #include "FWClnInf.h"
  30. #endif
  31.  
  32. #ifndef FWFRAME_H
  33. #include "FWFrame.h"
  34. #endif
  35.  
  36. #ifndef FWINTER_H
  37. #include "FWInter.h"
  38. #endif
  39.  
  40. #ifndef SLODFSTR_K
  41. #include "SLODFStr.k"
  42. #endif
  43.  
  44. #ifndef SLODFSTR_H
  45. #include "SLODFStr.h"
  46. #endif
  47.  
  48. #ifndef FWALERT_H
  49. #include "FWAlert.h"
  50. #endif
  51.  
  52. // ----- OpenDoc Includes -----
  53.  
  54. #ifndef SOM_ODDraft_xh
  55. #include <Draft.xh>
  56. #endif
  57.  
  58. #ifndef SOM_ODSession_xh
  59. #include <ODSessn.xh>
  60. #endif
  61.  
  62. #ifndef SOM_ODDraft_xh
  63. #include <Draft.xh>
  64. #endif
  65.  
  66. #ifndef SOM_ODDocument_xh
  67. #include <Document.xh>
  68. #endif
  69.  
  70. #ifndef SOM_ODStorageSystem_xh
  71. #include <ODStor.xh>
  72. #endif
  73.  
  74. #ifndef SOM_Module_OpenDoc_StdProps_defined
  75. #include <StdProps.xh>
  76. #endif
  77.  
  78. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  79. #include <StdTypes.xh>
  80. #endif
  81.  
  82. //========================================================================================
  83. //    Runtime Info
  84. //========================================================================================
  85.  
  86. #ifdef FW_BUILD_MAC
  87. #pragma segment fw_embedding
  88. #endif
  89.  
  90. //========================================================================================
  91. //    Global Methods
  92. //========================================================================================
  93.  
  94. //----------------------------------------------------------------------------------------
  95. // FW_AcquireFileContainer
  96. //----------------------------------------------------------------------------------------
  97.  
  98. ODContainer* FW_AcquireFileContainer(Environment* ev, ODSession* session, const FW_PFileSpecification& fileSpec)
  99. {
  100. #ifdef FW_BUILD_MAC
  101.     FSSpec macSpec;
  102.     fileSpec->MacGetFSSpec(ev, &macSpec);
  103.  
  104.     FW_CByteArray bArray(&macSpec, sizeof(short) + sizeof(long) + macSpec.name[0] + 1);
  105.     return session->GetStorageSystem(ev)->AcquireContainer(ev, kODDefaultFileContainer, bArray);
  106. #endif
  107.  
  108. #ifdef FW_BUILD_WIN
  109.     FW_DEBUG_MESSAGE("Not Yet Implemented");    
  110. #endif
  111. }
  112.     
  113. //----------------------------------------------------------------------------------------
  114. //    FW_InsertPartFromFile
  115. //----------------------------------------------------------------------------------------
  116.  
  117. FW_EInternalizeResult FW_InsertPartFromFile(Environment* ev, 
  118.                                             FW_CEmbeddingFrame* frame, 
  119.                                             const FW_PFileSpecification& fileSpec)
  120. {
  121.     FW_EInternalizeResult result = FW_kInternalizeFailed;
  122.  
  123.     ODSession* session = frame->GetPart(ev)->GetSession(ev);
  124.     
  125.     FW_CAcquiredODContainer aqContainer = ::FW_AcquireFileContainer(ev, session, fileSpec);
  126.     if (aqContainer != NULL)
  127.     {
  128.         // ----- Get the document -----
  129.         FW_CAcquiredODDocument documentToInsert = aqContainer->AcquireDocument(ev, kODDefaultDocument);
  130. /*        
  131.         //     [HLX] There is no way to test that I am trying to insert the same document. The following code
  132.         //    doesn't work. 
  133.         
  134.         // ----- Check we are not trying to insert itself -----
  135.         ODID id1 = frame->GetPart(ev)->GetDraft(ev)->GetDocument(ev)->GetID(ev);
  136.         ODID id2 = documentToInsert->GetID(ev);
  137.         if (id2 == id1)
  138.         {
  139.             FW_CString errorStr;
  140.             FW_CString32 partName;
  141.             frame->GetPart(ev)->GetPartName(ev, partName);
  142.             FW_PrivLoadODFString(ev, FW_kInsertSameDocument, errorStr);
  143.             FW_ErrorAlert(partName, errorStr);
  144.             return result;
  145.         }
  146. */        
  147.         // ----- Get the draft -----
  148.         FW_CAcquiredODDraft fromDraft = documentToInsert->AcquireBaseDraft(ev, kODDPReadOnly);
  149.         
  150.         while (documentToInsert->Exists(ev, 0, fromDraft, kODPosLastAbove))
  151.         {
  152.             fromDraft = documentToInsert->AcquireDraft(ev, 
  153.                                                         kODDPReadOnly,
  154.                                                         NULL, 
  155.                                                         fromDraft, 
  156.                                                         kODPosLastAbove,
  157.                                                         FALSE);
  158.         }
  159.  
  160.         FW_CAcquiredODStorageUnit fromSU = fromDraft->AcquireDraftProperties(ev);
  161.  
  162.         fromSU->Focus(ev, kODPropRootPartSU, kODPosUndefined, kODStrongStorageUnitRef, 0, kODPosUndefined);
  163.         
  164.         ODStorageUnitRef aSURef;
  165.         FW_CByteArray byteArray; 
  166.         fromSU->GetValue(ev, sizeof(aSURef), byteArray);
  167.         byteArray.CopyBuffer( &aSURef, sizeof(aSURef));
  168.  
  169.         FW_CAcquiredODStorageUnit aqInsertSU = fromDraft->AcquireStorageUnit(ev, fromSU->GetIDFromStorageUnitRef(ev, aSURef));
  170.         
  171.         FW_CPresentation* presentation = frame->GetPresentation(ev);
  172.         
  173.         // ----- Embed -----
  174.         ODPasteAsResult embedInfo;
  175.         
  176.         embedInfo.pasteLinkSetting     = FALSE;
  177.         embedInfo.autoUpdateSetting = FALSE;
  178.         embedInfo.mergeSetting         = FALSE;
  179.         embedInfo.selectedView         = presentation->GetDefaultEmbeddedFrameViewType(ev);
  180.         embedInfo.selectedKind         = NULL;
  181.         embedInfo.translateKind     = NULL;
  182.         embedInfo.editor             = kODNoEditor;
  183.  
  184.         FW_CPart* part = presentation->GetPart(ev);
  185.         FW_CSelection* selection = presentation->GetSelection(ev);
  186.         result = part->GetDataInterchange(ev)->InternalizeData(ev, selection->GetSelectedContent(ev), frame, aqInsertSU, FW_kFileStorage, kODClonePaste, &embedInfo);
  187.     }
  188.     
  189.     return result;
  190. }
  191.  
  192. //----------------------------------------------------------------------------------------
  193. //    FW_ClonePartFromFile
  194. //----------------------------------------------------------------------------------------
  195.  
  196. ODPart* FW_ClonePartFromFile(Environment* ev, FW_CEmbeddingFrame* scopeFrame, const FW_PFileSpecification& fileSpec)
  197. {
  198.     FW_ASSERT(scopeFrame);
  199.     
  200.     ODDraft* destDraft = scopeFrame->GetPart(ev)->GetDraft(ev);
  201.  
  202.     ODPart* clonedPart = NULL;
  203.  
  204.     ODSession* session = scopeFrame->GetPart(ev)->GetSession(ev);
  205.     
  206.     FW_CAcquiredODContainer aqContainer = ::FW_AcquireFileContainer(ev, session, fileSpec);
  207.     if (aqContainer != NULL)
  208.     {
  209.         // ----- Get the document -----
  210.         FW_CAcquiredODDocument documentToInsert = aqContainer->AcquireDocument(ev, kODDefaultDocument);
  211.  
  212.         // ----- Get the draft -----
  213.         FW_CAcquiredODDraft fromDraft = documentToInsert->AcquireBaseDraft(ev, kODDPReadOnly);
  214.         
  215.         while (documentToInsert->Exists(ev, 0, fromDraft, kODPosLastAbove))
  216.         {
  217.             fromDraft = documentToInsert->AcquireDraft(ev, 
  218.                                                         kODDPReadOnly,
  219.                                                         NULL, 
  220.                                                         fromDraft, 
  221.                                                         kODPosLastAbove,
  222.                                                         FALSE);
  223.         }
  224.  
  225.         FW_CAcquiredODStorageUnit fromSU = fromDraft->AcquireDraftProperties(ev);
  226.  
  227.         fromSU->Focus(ev, kODPropRootPartSU, kODPosUndefined, kODStrongStorageUnitRef, 0, kODPosUndefined);
  228.         
  229.         ODStorageUnitRef aSURef;
  230.         FW_CByteArray byteArray; 
  231.         fromSU->GetValue(ev, sizeof(aSURef), byteArray);
  232.         byteArray.CopyBuffer( &aSURef, sizeof(aSURef));
  233.  
  234.         FW_CAcquiredODStorageUnit aqInsertSU = fromDraft->AcquireStorageUnit(ev, fromSU->GetIDFromStorageUnitRef(ev, aSURef));
  235.         
  236.         FW_CCloneInfo cloneInfo(ev, fromDraft, scopeFrame, kODClonePaste);
  237.         cloneInfo.BeginClone(ev, destDraft);
  238.         
  239.         ODID clonedPartID = cloneInfo.Clone(ev, aqInsertSU->GetID(ev), 0, 0);
  240.         FW_ASSERT(clonedPartID != kODNULLID);
  241.  
  242.         cloneInfo.EndClone(ev);
  243.  
  244.         clonedPart = destDraft->AcquirePart(ev, clonedPartID);
  245.     }
  246.     
  247.     return clonedPart;
  248. }
  249.  
  250. #ifdef FW_BUILD_MAC
  251. //----------------------------------------------------------------------------------------
  252. //    FW_MacInsertFilterProc
  253. //----------------------------------------------------------------------------------------
  254.  
  255. pascal Boolean FW_MacInsertFilterProc(CInfoPBPtr pb)
  256. {
  257.     return (pb->hFileInfo.ioFlFndrInfo.fdCreator != 'odtm');    // remenber: TRUE suppresses display, FALSE allows display
  258. }
  259. #endif
  260.